****************************************************************************
*This file builds vars on migration flows across states from the Census/ACS*
****************************************************************************

use "$list/czones_list.dta", clear
expand 2
gen year=1990
bys czone: replace year=2000 if _n==2

merge m:1 czone using "$clean_data_lmarket/czone1990_MigrationFlowsState.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2000_MigrationFlowsState.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2008_MigrationFlowsState.dta", assert(3) nogenerate

*Normalized to one year
foreach year in 1990 2000 {
foreach state in mig_inSt mig_outSt {

*Student/migrants
gen `state'StudentsN4_`year' = (ipums_`state'_sc_a19_64_`year'/4)/ipums_pop_a19_64_`year'

}
}

foreach year in 2008 {
foreach state in mig_inSt mig_outSt {

*Students
gen `state'Students_`year' = (ipums_`state'_sc_a19_64_`year')/ipums_pop_a19_64_`year'

}
}


*Change in share of non-migrant students
foreach var in N4 {
foreach state in mig_inSt mig_outSt {

*Share of students/migrants
gen d_`state'Students`var' = 0.7*100*(`state'Students`var'_2000-`state'Students`var'_1990) if year == 1990
replace d_`state'Students`var' = 100*(`state'Students_2008-`state'Students`var'_2000) if year == 2000

}
}

save "$final_data_outcomes/czone_StudentMigrantsState.dta", replace



